# A valid snippet should starts with:
#
#		snippet trigger_word [ "description" [ options ] ]
#
# and end with:
#
#		endsnippet
#
# Snippet options:
#
#		b - Beginning of line.
#		i - In-word expansion.
#		w - Word boundary.
#		r - Regular expression
#		e - Custom context snippet
#		A - Snippet will be triggered automatically, when condition matches.
#
# Basic example:
#
#		snippet emitter "emitter properties" b
#		private readonly ${1} = new Emitter<$2>()
#		public readonly ${1/^_(.*)/$1/}: Event<$2> = this.$1.event
#		endsnippet
#
# Online reference: https://github.com/SirVer/ultisnips/blob/master/doc/UltiSnips.txt



snippet now "Description"
This is a test line, answer = `!p snip.rv = math()`
endsnippet

snippet test "Description"
This is a test line
endsnippet

snippet t
<tag>${VISUAl: inside text/should/is/g}</tag>
endsnippet





###########################
# Sections and Paragraphs #
###########################
snippet sec "Section" b
# ${1:Section Name} #
$0
endsnippet

snippet ssec "Sub Section" b
## ${1:Section Name} ##
$0
endsnippet

snippet sssec "SubSub Section" b
### ${1:Section Name} ###
$0
endsnippet

snippet par "Paragraph" b
#### ${1:Paragraph Name} ####
$0
endsnippet

snippet spar "Paragraph" b
##### ${1:Paragraph Name} #####
$0
endsnippet

###################
# Text formatting #
###################

snippet * "italics" b
*${1:${VISUAL}}*$0
endsnippet

snippet bold "bold" b
**${1:${VISUAL}}**$0
endsnippet

snippet ** "bold" b
**${1:${VISUAL}}**$0
endsnippet

snippet *** "bold italics" b
***${1:${VISUAL}}***$0
endsnippet

snippet /* "Comment" b
<!-- ${1:${VISUAL}} -->$0
endsnippet

# Create Table

post_jump "create_table(snip)"
snippet "tb([1-9][1-9])" "Fancy table" br
`!p snip.rv = match.group(1)`
endsnippet

# ==========================================================
# Math
# ==========================================================

# Envirmoent
snippet im "inline Math" b
\$$1\$ $0 
endsnippet

snippet dm "Display Math" b
\$\$
	$1
\$\$
endsnippet

snippet bmat "Matrix" b
\\begin{bmatrix}
$1
\\end{bmatrix}
endsnippet

snippet cases "Math Cases" b
\\begin{cases}
$1
\\end{cases}
endsnippet

snippet align "Math aligned" b
\\begin{aligned}
$1
\\end{aligned}
endsnippet

snippet bm "bold words" b
{\\bm ${1:${VISUAL}}}
endsnippet

snippet rm "Regular words" b
{\\rm ${1:${VISUAL}}}
endsnippet








# ==========================================================
# 常用字符
# ==========================================================

context "math()"
snippet ... "cdots" i
\cdots 
endsnippet

snippet != "equals" i
\neq 
endsnippet

snippet lim "limit" b
\lim_{${1:n} \to ${2:\infty}} 
endsnippet

snippet sr "^2" i
^2
endsnippet

snippet cb "^3" i
^3
endsnippet

snippet td "to the ... power" i
^{$1}$0
endsnippet

snippet tb "to the ... power" i
^{($1)}$0
endsnippet

snippet ooo "\infty" i
\infty
endsnippet

snippet <= "leq" i
\leq 
endsnippet

snippet >= "geq" i
\geq 
endsnippet

snippet EE "exist" i
\exists
endsnippet

snippet xnn "xn" i
x_{n}
endsnippet

snippet ynn "yn" i
y_{n}
endsnippet

snippet xx "cross" i
\times 
endsnippet

snippet ** "star" i
^{*}
endsnippet

snippet abs "abstract value" i
\left\vert $1 \right\vert $0
endsnippet

snippet -> "to" i
\to 
endsnippet

snippet inn "in " i
\in 
endsnippet

snippet cov "Covariance" i
\mathrm{Cov} 
endsnippet

snippet range "i = 1, \ldots, n" i
${1:i} = ${2:1}, \ldots, ${3:n}
endsnippet

snippet list "a_1, ..., a_n" i
${1:i}_${2:1}, \ldots, $1_${3:n}
endsnippet

# 希腊字母

snippet alpha "alpha" iA
\alpha
endsnippet

snippet beta "bata" iA
\beta
endsnippet

snippet gamma "gamma" iA
\gamma
endsnippet

snippet cf "calF" iA
\mathcal{F}
endsnippet

snippet cL "calL" iA
\mathcal{L}
endsnippet


# ========
# 上标
# ========


# ========
# 除法
# ========

snippet // "Fraction" i	
\\frac{$1}{$2}$0
endsnippet


snippet / "Fraction" i
\\frac{${VISUAL}}{$1}$0
endsnippet


priority 1000
snippet '((\d+)|(\d*)(\\)?([A-Za-z]+)((\^|_)(\{\d+\}|\d))*)/' "Fraction" wrA
\\frac{`!p snip.rv = match.group(1)`}{$1}$0
endsnippet


snippet '^.*\)/' "() frac" wr
`!p
stripped = match.string[:-1]
depth = 0
i = len(stripped) - 1
while True:
	if stripped[i] == ')': depth += 1
	if stripped[i] == '(': depth -= 1
	if depth == 0: break;
	i-=1
snip.rv = stripped[0:i] + "\\frac{" + stripped[i+1:-1] + "}"
`{$1}$0
endsnippet